From 205bd1d25b5f4d5c3d0e0b80e7d0a56958aff79d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 Jan 2015 08:07:26 -0800 Subject: [PATCH] Fix printing full descriptions on --verbose Previously an error's description was not printed at all if it was not a "human error". This alters the logic to always print the description on --verbose, as well as ensuring that --verbose is suggested if this is the case and we're not verbose. Closes #1201 --- src/cargo/lib.rs | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index baed1e5cd..7c6f6ddc5 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -154,7 +154,8 @@ pub fn handle_error(err: CliError, shell: &mut MultiShell) { let desc = error.description(); - if unknown { + let hide_desc = unknown && !shell.get_verbose(); + if hide_desc { output(Some("An unknown error occurred"), None, shell, fatal); } else if desc.len() > 0 { output(Some(desc), None, shell, fatal); @@ -162,7 +163,7 @@ pub fn handle_error(err: CliError, shell: &mut MultiShell) { if shell.get_verbose() { output(None, error.detail(), shell, fatal); } - if !handle_cause(&*error, shell) { + if !handle_cause(&*error, shell) || (hide_desc && !desc.is_empty()) { let _ = shell.err().say("\nTo learn more, run the command again \ with --verbose.".to_string(), BLACK); } @@ -214,30 +215,6 @@ fn flags_from_args<'a, T>(usage: &str, args: &[String], options_first: bool) -> CliResult where T: Decodable { - struct CargoDocoptError { err: docopt::Error } - impl Error for CargoDocoptError { - fn description(&self) -> &str { - match self.err { - docopt::Error::WithProgramUsage(..) => "", - ref e if e.fatal() => self.err.description(), - _ => "", - } - } - - fn detail(&self) -> Option { - match self.err { - docopt::Error::WithProgramUsage(_, ref usage) => { - Some(usage.clone()) - } - ref e if e.fatal() => None, - ref e => Some(e.to_string()) - } - } - } - impl CargoError for CargoDocoptError { - fn is_human(&self) -> bool { true } - } - let docopt = Docopt::new(usage).unwrap() .options_first(options_first) .argv(args.iter().map(|s| s.as_slice())) @@ -245,7 +222,12 @@ fn flags_from_args<'a, T>(usage: &str, args: &[String], .version(Some(version())); docopt.decode().map_err(|e| { let code = if e.fatal() {1} else {0}; - CliError::from_error(CargoDocoptError { err: e }, code) + let desc = match e { + docopt::Error::WithProgramUsage(_, s) => s, + ref e if e.fatal() => e.description().to_string(), + e => e.to_string(), + }; + CliError::from_error(human(desc), code) }) } -- 2.30.2